﻿#region zh-CHS 2006 - 2008 DemoSoft 团队 | en 2006 - 2008 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the MMOSE(Massively Multiplayer Online Server Engine) for .NET.
//
//                              2006-2008 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com
// 
// optimize BaseMap : Thank DanielChen

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Demo.Mmose.Core.Common;
using Demo.Mmose.Core.Common.SupportSlice;
using Demo.Mmose.Core.Entity;
using Demo.Mmose.Core.Entity.Character;
using Demo.Mmose.Core.Entity.Creature;
using Demo.Mmose.Core.Entity.Item;
using Demo.Mmose.Core.Util;
using Demo.Mmose.Core.World;
using Demo.Mmose.Core.Common.Component;
#endregion

// 可移动的物体
// 可视
// 更新血
// 移动
// 攻击
// 给出经验和道具
// 给出是否升级
// 检测是否上面已经更新则发送相应的数据包

// 道具的物体
// 清除已无效的掉落道具
// 可视
// 装备上
// 道具状态改变

// 地图
// 所有的道具
// 所有的人物

// 地图 -> 人物&道具

namespace Demo.Mmose.Core.Map
{
    // 地图的信息
    //////////////////////////////////////////////////////////////////////////
    // 给出某个坐标点范围内的数据(Mobile/Item/Client)
    // 
    // 
    // 
    // 
    // 
    // 
    // 

    /// <summary>
    /// 
    /// </summary>
    public class BaseMap : IComparable, IComparable<BaseMap>, ISupportSlice, IComponentHandler
    {
        #region zh-CHS 私有常量 | en Private Constants
        /// <summary>
        /// 
        /// </summary>
        private readonly static int LIST_CAPACITY_SMALL_SIZE = 20;
        #endregion

        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
        /// <summary>
        /// 
        /// </summary>
        public BaseMap()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mapID"></param>
        /// <param name="mapIndex"></param>
        /// <param name="fileIndex"></param>
        /// <param name="iWidth"></param>
        /// <param name="iHeight"></param>
        /// <param name="iSeason"></param>
        /// <param name="strName"></param>
        /// <param name="mapRules"></param>
        public BaseMap( Serial mapId, Rectangle3D mapRectangle, string strMapName )
        {
            m_MapId = mapId;
            m_MapRectangle = mapRectangle;
            m_MapName = strMapName;
        }
        #endregion

        #region zh-CHS 共有属性 | en Public Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        Rectangle3D m_MapRectangle = new Rectangle3D();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public Rectangle3D MapRectangle
        {
            get { return m_MapRectangle; }
            set { m_MapRectangle = value; }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private Serial m_MapId;
        #endregion
        /// <summary>
        /// 地图的ID
        /// </summary>
        public Serial MapId
        {
            get { return m_MapId; }
            set { m_MapId = value; }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 地图名
        /// </summary>
        private string m_MapName;
        #endregion
        /// <summary>
        /// 地图名
        /// </summary>
        public string MapName
        {
            get { return m_MapName; }
            set { m_MapName = value; }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 地图的全部地图点的数据
        /// </summary>
        private MapSpaceNode[, ,] m_SpaceNodes = null;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public MapSpaceNode[, ,] SpaceNodes
        {
            get { return m_SpaceNodes; }
        }

        #region zh-CHS World属性 | en World Properties

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 管理当前的世界服务
        /// </summary>
        private BaseWorld m_World = null;
        #endregion
        /// <summary>
        /// 管理当前的世界服务
        /// </summary>
        public BaseWorld World
        {
            get { return m_World; }
            internal set { m_World = value; }
        }

        #endregion

        #endregion

        #region zh-CHS 共有方法 | en Public Methods

        #region zh-CHS 分割地图内的区域点 | en
        /// <summary>
        /// 
        /// </summary>
        public virtual void ProcessPartitionSpace( IPartitionSpace partitionSpace )
        {
            if ( partitionSpace == null )
                throw new Exception( "BaseMap.ProcessPartitionSpace(...) - partitionSpace == null error!" );
            
            if ( this.EventInitMap != null )
                throw new Exception( "BaseMap.ProcessPartitionSpace(...) - this.EventInitMap != null error!" );

            // InitMap
            MapEventArgs mapEventArgs = new MapEventArgs( this );
            partitionSpace.InitMap( this, mapEventArgs );

            // PartitionSpace
            PartitionSpaceEventArgs partitionSpaceEventArgs = new PartitionSpaceEventArgs( this );
            partitionSpace.ProcessPartitionSpace( this, partitionSpaceEventArgs );

            if ( partitionSpaceEventArgs.PartitionSpace == null )
            {
                LOGs.WriteLine( LogMessageType.MSG_ERROR, "BaseMap.ProcessPartitionSpace(...) - eventArgs.PartitionSpace == null error!" );
                return;
            }
            else
            {
                this.EventInitMap += new EventHandler<MapEventArgs>( partitionSpace.InitMap );
                this.EventPartitionSpace += new EventHandler<PartitionSpaceEventArgs>( partitionSpace.ProcessPartitionSpace );
                this.EventGetSpaceNode += new EventHandler<GetSpaceNodeEventArgs>( partitionSpace.GetSpaceNod );
                this.EventGetSpaceNodesInRange += new EventHandler<GetGetSpaceNodesInRangeEventArgs>( partitionSpace.GetSpaceNodesInRange );

                m_SpaceNodes = partitionSpaceEventArgs.PartitionSpace;
            }

            for ( int iIndex0 = 0; iIndex0 < m_SpaceNodes.GetLength( 0 ); iIndex0++ )
            {
                for ( int iIndex1 = 0; iIndex1 < m_SpaceNodes.GetLength( 1 ); iIndex1++ )
                {
                    for ( int iIndex2 = 0; iIndex2 < m_SpaceNodes.GetLength( 2 ); iIndex2++ )
                    {
                        if ( m_SpaceNodes[iIndex0, iIndex1, iIndex2] != null )
                        {
                            m_SpaceNodes[iIndex0, iIndex1, iIndex2].RankIndex = new RankIndex( iIndex0, iIndex1, iIndex2 );
                            m_SpaceNodes[iIndex0, iIndex1, iIndex2].Owner = this;

                            m_SpaceNodes[iIndex0, iIndex1, iIndex2].ProcessPartitionSpace( partitionSpace );
                        }
                    }
                }
            }
        }
        #endregion

        #region zh-CHS 给出坐标获取地图内的某个区域点 | en
        /// <summary>
        /// 给出x,y点的地图该点的数据
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public MapSpaceNode GetSpaceNode( Point2D point2D )
        {
            return GetSpaceNode( point2D.X, point2D.Y, 0 );
        }

        /// <summary>
        /// 给出x,y点的地图该点的数据
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public MapSpaceNode GetSpaceNode( IPoint2D point2D )
        {
            return GetSpaceNode( point2D.X, point2D.Y, 0 );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public MapSpaceNode GetSpaceNode( float x, float y )
        {
            return GetSpaceNode( x, y, 0 );
        }

        /// <summary>
        /// 给出x,y点的地图该点的数据
        /// </summary>
        /// <param name="point3D"></param>
        /// <returns></returns>
        public MapSpaceNode GetSpaceNode( Point3D point3D )
        {
            return GetSpaceNode( point3D.X, point3D.Y, point3D.Z );
        }

        /// <summary>
        /// 给出x,y点的地图该点的数据
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public MapSpaceNode GetSpaceNode( IPoint3D point3D )
        {
            return GetSpaceNode( point3D.X, point3D.Y, point3D.Z );
        }

        /// <summary>
        /// 给出x,y点的地图该点的数据
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public MapSpaceNode GetSpaceNode( float x, float y, float z )
        {
            if ( this.EventGetSpaceNode != null )
            {
                GetSpaceNodeEventArgs eventArgs = new GetSpaceNodeEventArgs( x, y, z, this );
                this.EventGetSpaceNode( this, eventArgs );

                return eventArgs.SpaceNode;
            }

            return null;
        }
        #endregion

        #region zh-CHS 给出坐标范围获取地图内的多个区域点 | en
        /// <summary>
        /// 给出x,y点的地图该点的数据
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public MapSpaceNode[] GetSpaceNodesInRange( Point2D point2D, float fRange )
        {
            return GetSpaceNodesInRange( point2D.X, point2D.Y, 0, fRange );
        }

        /// <summary>
        /// 给出x,y点的地图该点的数据
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public MapSpaceNode[] GetSpaceNodesInRange( IPoint2D point2D, float fRange )
        {
            return GetSpaceNodesInRange( point2D.X, point2D.Y, 0, fRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public MapSpaceNode[] GetSpaceNodesInRange( float x, float y, float fRange )
        {
            return GetSpaceNodesInRange( x, y, 0, fRange );
        }

        /// <summary>
        /// 给出x,y点的地图该点的数据
        /// </summary>
        /// <param name="point3D"></param>
        /// <returns></returns>
        public MapSpaceNode[] GetSpaceNodesInRange( Point3D point3D, float fRange )
        {
            return GetSpaceNodesInRange( point3D.X, point3D.Y, point3D.Z, fRange );
        }

        /// <summary>
        /// 给出x,y点的地图该点的数据
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public MapSpaceNode[] GetSpaceNodesInRange( IPoint3D point3D, float fRange )
        {
            return GetSpaceNodesInRange( point3D.X, point3D.Y, point3D.Z, fRange );
        }

        #region zh-CHS 私有静态成员变量 | en Private Static Member Variables
        /// <summary>
        /// 
        /// </summary>
        private readonly static MapSpaceNode[] s_NullSpaceNodeArray = new MapSpaceNode[0];
        #endregion
        /// <summary>
        /// 给出x,y点的地图该点的数据
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public MapSpaceNode[] GetSpaceNodesInRange( float x, float y, float z, float fRange )
        {
            if ( this.EventGetSpaceNodesInRange != null )
            {
                GetGetSpaceNodesInRangeEventArgs eventArgs = new GetGetSpaceNodesInRangeEventArgs( x, y, z, Math.Abs( fRange ), this );
                this.EventGetSpaceNodesInRange( this, eventArgs );

                return eventArgs.SpaceNodes;
            }

            return s_NullSpaceNodeArray;
        }
        #endregion

        #region zh-CHS 进入或离开地图区域点 | en

        /// <summary>
        /// 道具进入新的地图区域点
        /// </summary>
        /// <param name="item"></param>
        public bool OnEnter( GameEntity entity )
        {
            EventHandler<BeforeEntityEnterMapEventArgs> tempBeforeEventArgs = m_EventBeforeEntityEnterMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeEntityEnterMapEventArgs eventArgs = new BeforeEntityEnterMapEventArgs( entity, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode mapSpaceNode = this.GetSpaceNode( entity );
            if ( mapSpaceNode == null )
                return false;
            else
            {
                if ( mapSpaceNode != entity.MapSpaceNode )
                {
                    mapSpaceNode.OnEnter( entity );
                    entity.MapSpaceNode = mapSpaceNode;
                }
            }

            EventHandler<AfterEntityEnterMapEventArgs> tempAfterEventArgs = m_EventAfterEntityEnterMap;
            if ( tempAfterEventArgs != null )
            {
                AfterEntityEnterMapEventArgs eventArgs = new AfterEntityEnterMapEventArgs( entity, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 道具进入新的地图区域点
        /// </summary>
        /// <param name="item"></param>
        public bool OnEnter( BaseItem item )
        {
            EventHandler<BeforeItemEnterMapEventArgs> tempBeforeEventArgs = m_EventBeforeItemEnterMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeItemEnterMapEventArgs eventArgs = new BeforeItemEnterMapEventArgs( item, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode mapSpaceNode = this.GetSpaceNode( item );
            if ( mapSpaceNode == null )
                return false;
            else
            {
                if ( mapSpaceNode != item.MapSpaceNode )
                {
                    mapSpaceNode.OnEnter( item );
                    item.MapSpaceNode = mapSpaceNode;
                }
            }

            EventHandler<AfterItemEnterMapEventArgs> tempAfterEventArgs = m_EventAfterItemEnterMap;
            if ( tempAfterEventArgs != null )
            {
                AfterItemEnterMapEventArgs eventArgs = new AfterItemEnterMapEventArgs( item, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 人物进入新的地图区域点
        /// </summary>
        /// <param name="m"></param>
        public bool OnEnter( BaseCreature creature )
        {
            EventHandler<BeforeCreatureEnterMapEventArgs> tempBeforeEventArgs = m_EventBeforeCreatureEnterMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeCreatureEnterMapEventArgs eventArgs = new BeforeCreatureEnterMapEventArgs( creature, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode mapSpaceNode = this.GetSpaceNode( creature );
            if ( mapSpaceNode == null )
                return false;
            else
            {
                if ( mapSpaceNode != creature.MapSpaceNode )
                {
                    mapSpaceNode.OnEnter( creature );
                    creature.MapSpaceNode = mapSpaceNode;
                }
            }

            EventHandler<AfterCreatureEnterMapEventArgs> tempAfterEventArgs = m_EventAfterCreatureEnterMap;
            if ( tempAfterEventArgs != null )
            {
                AfterCreatureEnterMapEventArgs eventArgs = new AfterCreatureEnterMapEventArgs( creature, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 人物进入新的地图区域点
        /// </summary>
        /// <param name="m"></param>
        public bool OnEnter( BaseCharacter character )
        {
            EventHandler<BeforeCharacterEnterMapEventArgs> tempBeforeEventArgs = m_EventBeforeCharacterEnterMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeCharacterEnterMapEventArgs eventArgs = new BeforeCharacterEnterMapEventArgs( character, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode mapSpaceNode = this.GetSpaceNode( character );
            if ( mapSpaceNode == null )
                return false;
            else
            {
                if ( mapSpaceNode != character.MapSpaceNode )
                {
                    mapSpaceNode.OnEnter( character );
                    character.MapSpaceNode = mapSpaceNode;
                }
            }

            EventHandler<AfterCharacterEnterMapEventArgs> tempAfterEventArgs = m_EventAfterCharacterEnterMap;
            if ( tempAfterEventArgs != null )
            {
                AfterCharacterEnterMapEventArgs eventArgs = new AfterCharacterEnterMapEventArgs( character, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 道具离开新的地图区域点
        /// </summary>
        /// <param name="item"></param>
        public bool OnLeave( GameEntity entity )
        {
            EventHandler<BeforeEntityLeaveMapEventArgs> tempBeforeEventArgs = m_EventBeforeEntityLeaveMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeEntityLeaveMapEventArgs eventArgs = new BeforeEntityLeaveMapEventArgs( entity, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode mapSpaceNode = this.GetSpaceNode( entity );
            if ( mapSpaceNode == null )
                return false;
            else
            {
                if ( mapSpaceNode != entity.MapSpaceNode )
                {
                    mapSpaceNode.OnLeave( entity );
                    entity.MapSpaceNode = null;
                }
            }

            EventHandler<AfterEntityLeaveMapEventArgs> tempAfterEventArgs = m_EventAfterEntityLeaveMap;
            if ( tempAfterEventArgs != null )
            {
                AfterEntityLeaveMapEventArgs eventArgs = new AfterEntityLeaveMapEventArgs( entity, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 道具离开新的地图区域点
        /// </summary>
        /// <param name="item"></param>
        public bool OnLeave( BaseItem item )
        {
            EventHandler<BeforeItemLeaveMapEventArgs> tempBeforeEventArgs = m_EventBeforeItemLeaveMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeItemLeaveMapEventArgs eventArgs = new BeforeItemLeaveMapEventArgs( item, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode mapSpaceNode = this.GetSpaceNode( item );
            if ( mapSpaceNode == null )
                return false;
            else
            {
                if ( mapSpaceNode != item.MapSpaceNode )
                {
                    mapSpaceNode.OnLeave( item );
                    item.MapSpaceNode = null;
                }
            }

            EventHandler<AfterItemLeaveMapEventArgs> tempAfterEventArgs = m_EventAfterItemLeaveMap;
            if ( tempAfterEventArgs != null )
            {
                AfterItemLeaveMapEventArgs eventArgs = new AfterItemLeaveMapEventArgs( item, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 人物离开新的地图区域点
        /// </summary>
        /// <param name="m"></param>
        public bool OnLeave( BaseCreature creature )
        {
            EventHandler<BeforeCreatureLeaveMapEventArgs> tempBeforeEventArgs = m_EventBeforeCreatureLeaveMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeCreatureLeaveMapEventArgs eventArgs = new BeforeCreatureLeaveMapEventArgs( creature, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode mapSpaceNode = this.GetSpaceNode( creature );
            if ( mapSpaceNode == null )
                return false;
            else
            {
                if ( mapSpaceNode != creature.MapSpaceNode )
                {
                    mapSpaceNode.OnLeave( creature );
                    creature.MapSpaceNode = null;
                }
            }

            EventHandler<AfterCreatureLeaveMapEventArgs> tempAfterEventArgs = m_EventAfterCreatureLeaveMap;
            if ( tempAfterEventArgs != null )
            {
                AfterCreatureLeaveMapEventArgs eventArgs = new AfterCreatureLeaveMapEventArgs( creature, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 人物离开新的地图区域点
        /// </summary>
        /// <param name="m"></param>
        public bool OnLeave( BaseCharacter character )
        {
            EventHandler<BeforeCharacterLeaveMapEventArgs> tempBeforeEventArgs = m_EventBeforeCharacterLeaveMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeCharacterLeaveMapEventArgs eventArgs = new BeforeCharacterLeaveMapEventArgs( character, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }


            MapSpaceNode mapSpaceNode = this.GetSpaceNode( character );
            if ( mapSpaceNode == null )
                return false;
            else
            {
                if ( mapSpaceNode != character.MapSpaceNode )
                {
                    mapSpaceNode.OnLeave( character );
                    character.MapSpaceNode = null;
                }
            }

            EventHandler<AfterCharacterLeaveMapEventArgs> tempAfterEventArgs = m_EventAfterCharacterLeaveMap;
            if ( tempAfterEventArgs != null )
            {
                AfterCharacterLeaveMapEventArgs eventArgs = new AfterCharacterLeaveMapEventArgs( character, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 道具移动到旧的地图区域点, 并离开新的地图区域点
        /// </summary>
        /// <param name="oldLocation"></param>
        /// <param name="item"></param>
        public bool OnMove( Point3D oldLocation, GameEntity entity )
        {
            EventHandler<BeforeEntityMoveInMapEventArgs> tempBeforeEventArgs = m_EventBeforeEntityMoveInMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeEntityMoveInMapEventArgs eventArgs = new BeforeEntityMoveInMapEventArgs( oldLocation, entity, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode oldMapSpaceNode = this.GetSpaceNode( oldLocation );
            if ( oldMapSpaceNode == null )
                return false;

            MapSpaceNode newMapSpaceNode = this.GetSpaceNode( entity.Location );
            if ( newMapSpaceNode == null )
                return false;

            if ( oldMapSpaceNode != newMapSpaceNode )
            {
                oldMapSpaceNode.OnLeave( entity );
                entity.MapSpaceNode = null;

                newMapSpaceNode.OnEnter( entity );
                entity.MapSpaceNode = newMapSpaceNode;
            }

            EventHandler<AfterEntityMoveInMapEventArgs> tempAfterEventArgs = m_EventAfterEntityMoveInMap;
            if ( tempAfterEventArgs != null )
            {
                AfterEntityMoveInMapEventArgs eventArgs = new AfterEntityMoveInMapEventArgs( oldLocation, entity, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 道具移动到旧的地图区域点, 并离开新的地图区域点
        /// </summary>
        /// <param name="oldLocation"></param>
        /// <param name="item"></param>
        public bool OnMove( Point3D oldLocation, BaseItem item )
        {
            EventHandler<BeforeItemMoveInMapEventArgs> tempBeforeEventArgs = m_EventBeforeItemMoveInMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeItemMoveInMapEventArgs eventArgs = new BeforeItemMoveInMapEventArgs( oldLocation, item, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode oldMapSpaceNode = this.GetSpaceNode( oldLocation );
            if ( oldMapSpaceNode == null )
                return false;

            MapSpaceNode newMapSpaceNode = this.GetSpaceNode( item.Location );
            if ( newMapSpaceNode == null )
                return false;

            if ( oldMapSpaceNode != newMapSpaceNode )
            {
                oldMapSpaceNode.OnLeave( item );
                item.MapSpaceNode = null;

                newMapSpaceNode.OnEnter( item );
                item.MapSpaceNode = newMapSpaceNode;
            }

            EventHandler<AfterItemMoveInMapEventArgs> tempAfterEventArgs = m_EventAfterItemMoveInMap;
            if ( tempAfterEventArgs != null )
            {
                AfterItemMoveInMapEventArgs eventArgs = new AfterItemMoveInMapEventArgs( oldLocation, item, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 人物移动到新的地图区域点, 并离开旧的地图区域点
        /// </summary>
        /// <param name="oldLocation"></param>
        /// <param name="m"></param>
        public bool OnMove( Point3D oldLocation, BaseCreature creature )
        {
            EventHandler<BeforeCreatureMoveInMapEventArgs> tempBeforeEventArgs = m_EventBeforeCreatureMoveInMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeCreatureMoveInMapEventArgs eventArgs = new BeforeCreatureMoveInMapEventArgs( oldLocation, creature, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode oldMapSpaceNode = this.GetSpaceNode( oldLocation );
            if ( oldMapSpaceNode == null )
                return false;

            MapSpaceNode newMapSpaceNode = this.GetSpaceNode( creature.Location );
            if ( newMapSpaceNode == null )
                return false;

            if ( oldMapSpaceNode != newMapSpaceNode )
            {
                oldMapSpaceNode.OnLeave( creature );
                creature.MapSpaceNode = null;

                newMapSpaceNode.OnEnter( creature );
                creature.MapSpaceNode = newMapSpaceNode;
            }

            EventHandler<AfterCreatureMoveInMapEventArgs> tempAfterEventArgs = m_EventAfterCreatureMoveInMap;
            if ( tempAfterEventArgs != null )
            {
                AfterCreatureMoveInMapEventArgs eventArgs = new AfterCreatureMoveInMapEventArgs( oldLocation, creature, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }

        /// <summary>
        /// 人物移动到新的地图区域点, 并离开旧的地图区域点
        /// </summary>
        /// <param name="oldLocation"></param>
        /// <param name="m"></param>
        public bool OnMove( Point3D oldLocation, BaseCharacter character )
        {
            EventHandler<BeforeCharacterMoveInMapEventArgs> tempBeforeEventArgs = m_EventBeforeCharacterMoveInMap;
            if ( tempBeforeEventArgs != null )
            {
                BeforeCharacterMoveInMapEventArgs eventArgs = new BeforeCharacterMoveInMapEventArgs( oldLocation, character, this );
                tempBeforeEventArgs( this, eventArgs );

                if ( eventArgs.IsCancel == true )
                    return false;
            }

            MapSpaceNode oldMapSpaceNode = this.GetSpaceNode( oldLocation );
            if ( oldMapSpaceNode == null )
                return false;

            MapSpaceNode newMapSpaceNode = this.GetSpaceNode( character.Location );
            if ( newMapSpaceNode == null )
                return false;

            if ( oldMapSpaceNode != newMapSpaceNode )
            {
                oldMapSpaceNode.OnLeave( character );
                character.MapSpaceNode = null;

                newMapSpaceNode.OnEnter( character );
                character.MapSpaceNode = newMapSpaceNode;
            }

            EventHandler<AfterCharacterMoveInMapEventArgs> tempAfterEventArgs = m_EventAfterCharacterMoveInMap;
            if ( tempAfterEventArgs != null )
            {
                AfterCharacterMoveInMapEventArgs eventArgs = new AfterCharacterMoveInMapEventArgs( oldLocation, character, this );
                tempAfterEventArgs( this, eventArgs );
            }

            return true;
        }
        #endregion

        #region zh-CHS 给出某个坐标点范围内的数据(GameEntity/BaseCreature/BaseItem/BaseCharacter/AllGameEntity) | en

        #region zh-CHS 给出 GameEntitys 的数据 | en
        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<GameEntityT> GetEntitysInRange<GameEntityT>( Point3D point3D, int iRange ) where GameEntityT : GameEntity
        {
            return GetEntitysInRange<GameEntityT>( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<GameEntityT> GetEntitysInRange<GameEntityT>( IPoint3D point3D, int iRange ) where GameEntityT : GameEntity
        {
            return GetEntitysInRange<GameEntityT>( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<GameEntityT> GetEntitysInRange<GameEntityT>( float x, float y, float z, int iRange ) where GameEntityT : GameEntity
        {
            MapSpaceNode[] mapSpaceNodeArray = this.GetSpaceNodesInRange( x, y, z, iRange );
            if ( mapSpaceNodeArray == null )
                yield break;

            List<GameEntity[]> entityArrayList = new List<GameEntity[]>( LIST_CAPACITY_SMALL_SIZE );

            foreach ( MapSpaceNode MapSpaceNode in mapSpaceNodeArray )
                entityArrayList.Add( MapSpaceNode.ToArrayInEntitys() );

            Rectangle3D rectangle3D = new Rectangle3D( new Point3D( x - iRange, y - iRange, z - iRange ), new Point3D( x + iRange, y + iRange, z + iRange ) );

            foreach ( GameEntity[] gameEntityArray in entityArrayList )
            {
                foreach ( GameEntity gameEntity in gameEntityArray )
                {
                    GameEntityT gameEntityT = gameEntity as GameEntityT;
                    if ( gameEntityT == default( GameEntityT ) )
                        continue;

                    if ( rectangle3D.Contains( gameEntityT.Location ) == false )
                        continue;

                    yield return gameEntityT;
                }
            }
        }
        #endregion

        #region zh-CHS 给出 Items 的数据 | en
        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<ItemT> GetItemsInRange<ItemT>( Point3D point3D, int iRange ) where ItemT : BaseItem
        {
            return GetItemsInRange<ItemT>( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<ItemT> GetItemsInRange<ItemT>( IPoint3D point3D, int iRange ) where ItemT : BaseItem
        {
            return GetItemsInRange<ItemT>( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<ItemT> GetItemsInRange<ItemT>( float x, float y, float z, int iRange ) where ItemT : BaseItem
        {
            MapSpaceNode[] mapSpaceNodeArray = this.GetSpaceNodesInRange( x, y, z, iRange );
            if ( mapSpaceNodeArray == null )
                yield break;

            List<BaseItem[]> itemArrayList = new List<BaseItem[]>( LIST_CAPACITY_SMALL_SIZE );

            foreach(MapSpaceNode MapSpaceNode in mapSpaceNodeArray)
                itemArrayList.Add( MapSpaceNode.ToArrayInItems() );

            Rectangle3D rectangle3D = new Rectangle3D( new Point3D( x - iRange, y - iRange, z - iRange ), new Point3D( x + iRange, y + iRange, z + iRange ) );

            foreach ( BaseItem[] itemArray in itemArrayList )
            {
                foreach ( BaseItem item in itemArray )
                {
                    ItemT itemT = item as ItemT;
                    if ( itemT == default( ItemT ) )
                        continue;

                    if ( rectangle3D.Contains( itemT.Location ) == false )
                        continue;

                    yield return itemT;
                }
            }
        }
        #endregion

        #region zh-CHS 给出 Creatures 的数据 | en
        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<CreatureT> GetCreaturesInRange<CreatureT>( Point3D point3D, int iRange ) where CreatureT : BaseCreature
        {
            return GetCreaturesInRange<CreatureT>( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<CreatureT> GetCreaturesInRange<CreatureT>( IPoint3D point3D, int iRange ) where CreatureT : BaseCreature
        {
            return GetCreaturesInRange<CreatureT>( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<CreatureT> GetCreaturesInRange<CreatureT>( float x, float y, float z, int iRange ) where CreatureT : BaseCreature
        {
            MapSpaceNode[] mapSpaceNodeArray = this.GetSpaceNodesInRange( x, y, z, iRange );
            if ( mapSpaceNodeArray == null )
                yield break;

            List<BaseCreature[]> creatureArrayList = new List<BaseCreature[]>( LIST_CAPACITY_SMALL_SIZE );

            foreach ( MapSpaceNode MapSpaceNode in mapSpaceNodeArray )
                creatureArrayList.Add( MapSpaceNode.ToArrayInCreatures() );

            Rectangle3D rectangle3D = new Rectangle3D( new Point3D( x - iRange, y - iRange, z - iRange ), new Point3D( x + iRange, y + iRange, z + iRange ) );

            foreach ( BaseCreature[] creatureArray in creatureArrayList )
            {
                foreach ( BaseCreature creature in creatureArray )
                {
                    CreatureT creatureT = creature as CreatureT;
                    if ( creatureT == default( CreatureT ) )
                        continue;

                    if ( rectangle3D.Contains( creatureT.Location ) == false )
                        continue;

                    yield return creatureT;
                }
            }
        }
        #endregion

        #region zh-CHS 给出 Players 的数据 | en
        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<CharacterT> GetPlayersInRange<CharacterT>( Point3D point3D, int iRange ) where CharacterT : BaseCharacter
        {
            return GetPlayersInRange<CharacterT>( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<CharacterT> GetPlayersInRange<CharacterT>( IPoint3D point3D, int iRange ) where CharacterT : BaseCharacter
        {
            return GetPlayersInRange<CharacterT>( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<CharacterT> GetPlayersInRange<CharacterT>( float x, float y, float z, int iRange ) where CharacterT : BaseCharacter
        {
            MapSpaceNode[] mapSpaceNodeArray = this.GetSpaceNodesInRange( x, y, z, iRange );
            if ( mapSpaceNodeArray == null )
                yield break;

            List<BaseCharacter[]> characterArrayList = new List<BaseCharacter[]>( LIST_CAPACITY_SMALL_SIZE );

            foreach ( MapSpaceNode MapSpaceNode in mapSpaceNodeArray )
                characterArrayList.Add( MapSpaceNode.ToArrayInPlayers() );

            Rectangle3D rectangle3D = new Rectangle3D( new Point3D( x - iRange, y - iRange, z - iRange ), new Point3D( x + iRange, y + iRange, z + iRange ) );
            
            foreach ( BaseCharacter[] characterArray in characterArrayList )
            {
                foreach ( BaseCharacter character in characterArray )
                {
                    CharacterT characterT = character as CharacterT;
                    if ( characterT == default( CharacterT ) )
                        continue;

                    if ( rectangle3D.Contains( characterT.Location ) == false )
                        continue;

                    yield return characterT;
                }
            }
        }
        #endregion

        #region zh-CHS 给出 GetAllEntitys 的数据 | en
        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<GameEntity> GetAllEntitysInRange( Point3D point3D, int iRange )
        {
            return GetAllEntitysInRange( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<GameEntity> GetAllEntitysInRange( IPoint3D point3D, int iRange )
        {
            return GetAllEntitysInRange( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public IEnumerable<GameEntity> GetAllEntitysInRange( float x, float y, float z, int iRange )
        {
            MapSpaceNode[] mapSpaceNodeArray = this.GetSpaceNodesInRange( x, y, z, iRange );
            if ( mapSpaceNodeArray == null )
                yield break;

            List<GameEntity[]> entityArrayList = new List<GameEntity[]>( LIST_CAPACITY_SMALL_SIZE );

            foreach ( MapSpaceNode MapSpaceNode in mapSpaceNodeArray )
            {
                entityArrayList.Add( MapSpaceNode.ToArrayInEntitys() );
                entityArrayList.Add( MapSpaceNode.ToArrayInItems() );
                entityArrayList.Add( MapSpaceNode.ToArrayInCreatures() );
                entityArrayList.Add( MapSpaceNode.ToArrayInPlayers() );
            }

            Rectangle3D rectangle3D = new Rectangle3D( new Point3D( x - iRange, y - iRange, z - iRange ), new Point3D( x + iRange, y + iRange, z + iRange ) );
            
            foreach ( GameEntity[] gameEntityArray in entityArrayList )
            {
                foreach ( GameEntity gameEntity in gameEntityArray )
                {
                    if ( gameEntity == null )
                        continue;

                    if ( rectangle3D.Contains( gameEntity.Location ) == false )
                        continue;

                    yield return gameEntity;
                }
            }
        }
        #endregion

        #endregion

        #region zh-CHS 在区域内的某个坐标点是否可刷怪 | en
        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <returns></returns>
        public bool CanSpawn( Point3D point3D )
        {
            return CanSpawn( point3D.X, point3D.Y, point3D.Z );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point3D"></param>
        /// <returns></returns>
        public bool CanSpawn( IPoint3D point3D )
        {
            return CanSpawn( point3D.X, point3D.Y, point3D.Z );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point2D"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public bool CanSpawn( Point2D point2D, float z )
        {
            return CanSpawn( point2D.X, point2D.Y, z );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="point2D"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public bool CanSpawn( IPoint2D point2D, float z )
        {
            return CanSpawn( point2D.X, point2D.Y, z );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public bool CanSpawn( float x, float y, float z )
        {
            EventHandler<CanSpawnEventArgs> tempEventArgs = m_EventCanSpawn;
            if ( tempEventArgs != null )
            {
                CanSpawnEventArgs eventArgs = new CanSpawnEventArgs( x, y, z, this );
                tempEventArgs( this, eventArgs );

                return eventArgs.IsCanSpawn;
            }

            return true;
        }
        #endregion

        #region zh-CHS 地图区域点是否有玩家存在 | en
        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool PlayersInRange( Point2D point2D, int iRange )
        {
            return PlayersInRange( point2D.X, point2D.Y, iRange );
        }

        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool PlayersInRange( IPoint2D point2D, int iRange )
        {
            return PlayersInRange( point2D.X, point2D.Y, iRange );
        }

        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool PlayersInRange( float x, float y, int iRange )
        {
            return PlayersInRange( x, y, 0, iRange );
        }

        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool PlayersInRange( Point3D point3D, int iRange )
        {
            return PlayersInRange( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool PlayersInRange( IPoint3D point3D, int iRange )
        {
            return PlayersInRange( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool PlayersInRange( float x, float y, float z, int iRange )
        {
            IEnumerable<BaseCharacter> enumerable = this.GetPlayersInRange<BaseCharacter>( x, y, z, iRange );
            if ( enumerable == null )
                return false;

            bool bIsPlayersInRange = false;

            foreach ( BaseCharacter character in enumerable )
            {
                bIsPlayersInRange = true; // > 1
                break;
            }

            return bIsPlayersInRange;
        }
        #endregion

        #region zh-CHS 地图区域点是否有人物存在 | en
        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool CreaturesInRange( Point2D point2D, int iRange )
        {
            return CreaturesInRange( point2D.X, point2D.Y, iRange );
        }

        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool CreaturesInRange( IPoint2D point2D, int iRange )
        {
            return CreaturesInRange( point2D.X, point2D.Y, iRange );
        }

        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool CreaturesInRange( float x, float y, int iRange )
        {
            return CreaturesInRange( x, y, 0, iRange );
        }

        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool CreaturesInRange( Point3D point3D, int iRange )
        {
            return CreaturesInRange( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool CreaturesInRange( IPoint3D point3D, int iRange )
        {
            return CreaturesInRange( point3D.X, point3D.Y, point3D.Z, iRange );
        }

        /// <summary>
        /// 检查某个区域内是否有玩家存在
        /// </summary>
        /// <param name="sector"></param>
        /// <param name="iRange"></param>
        /// <returns></returns>
        public bool CreaturesInRange( float x, float y, float z, int iRange )
        {
            IEnumerable<BaseCreature> enumerable = this.GetCreaturesInRange<BaseCreature>( x, y, z, iRange );
            if ( enumerable == null )
                return false;

            bool bIsCreaturesInRange = false;

            foreach ( BaseCharacter character in enumerable )
            {
                bIsCreaturesInRange = true; // > 1
                break;
            }

            return bIsCreaturesInRange;
        }
        #endregion

        #region zh-CHS 确保坐标点在地图的边界内 | en
        /// <summary>
        /// 确保Point2D坐标点在地图的边界内
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public Point2D Bound( Point2D point2D )
        {
            return Bound( point2D.X, point2D.Y );
        }

        /// <summary>
        /// 确保Point2D坐标点在地图的边界内
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public Point2D Bound( IPoint2D point2D )
        {
            return Bound( point2D.X, point2D.Y );
        }

        /// <summary>
        /// 确保x,y在地图的边界内
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="newX"></param>
        /// <param name="newY"></param>
        public Point2D Bound( float x, float y )
        {
            float newX = 0;
            float newY = 0;

            if ( x < m_MapRectangle.Start.X )
                newX = m_MapRectangle.Start.X;
            else if ( x > m_MapRectangle.End.X )
                newX = m_MapRectangle.End.X;
            else
                newX = x;

            if ( y < m_MapRectangle.Start.Y )
                newY = m_MapRectangle.Start.Y;
            else if ( y > m_MapRectangle.End.Y )
                newY = m_MapRectangle.End.Y;
            else
                newY = y;

            return new Point2D( newX, newY );
        }

        /// <summary>
        /// 确保Point3D坐标点在地图的边界内
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public Point3D Bound( Point3D point3D )
        {
            return Bound( point3D.X, point3D.Y, point3D.Z );
        }

        /// <summary>
        /// 确保Point3D坐标点在地图的边界内
        /// </summary>
        /// <param name="point2D"></param>
        /// <returns></returns>
        public Point3D Bound( IPoint3D point3D )
        {
            return Bound( point3D.X, point3D.Y, point3D.Z );
        }

        /// <summary>
        /// 确保x,y,z在地图的边界内
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="newX"></param>
        /// <param name="newY"></param>
        public Point3D Bound( float x, float y, float z )
        {
            float newX = 0;
            float newY = 0;
            float newZ = 0;

            if ( x < m_MapRectangle.Start.X )
                newX = m_MapRectangle.Start.X;
            else if ( x > m_MapRectangle.End.X )
                newX = m_MapRectangle.End.X;
            else
                newX = x;

            if ( y < m_MapRectangle.Start.Y )
                newY = m_MapRectangle.Start.Y;
            else if ( y > m_MapRectangle.End.Y )
                newY = m_MapRectangle.End.Y;
            else
                newY = y;

            if ( z < m_MapRectangle.Start.Z )
                newZ = m_MapRectangle.Start.Z;
            else if ( z > m_MapRectangle.End.Z )
                newZ = m_MapRectangle.End.Z;
            else
                newZ = z;

            return new Point3D( newX, newY, newZ );
        }
        #endregion

        #region zh-CHS 地图的主处理行为 | en
        /// <summary>
        /// 
        /// </summary>
        public virtual void ProcessSlice()
        {
            EventHandler<MapEventArgs> tempEventArgs = m_EventSlice;
            if ( tempEventArgs != null )
            {
                MapEventArgs eventArgs = new MapEventArgs( this );
                tempEventArgs( this, eventArgs );
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public static void UpdateSliceTo<thisT>( IUpdateSlice<thisT> updateSlice, thisT mapT ) where thisT : BaseMap
        {
            if ( updateSlice == null )
                throw new Exception( "BaseMap.Slice(...) - updateSlice == null error!" );

            if ( mapT == null )
                throw new Exception( "BaseMap.Slice(...) - mapT == null error!" );

            updateSlice.UpdateSlice( mapT );

            BaseWorld tempWorld = mapT.World;
            if ( tempWorld != null )
                tempWorld.SetWorldSignal();
            else
                throw new Exception( "BaseMap.Slice(...) - tempWorld == null error!" );
        }
        #endregion

        #endregion

        #region zh-CHS 方法覆盖 | en Override Methods
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return m_MapName;
        }
        #endregion

        #region zh-CHS 接口实现 | en Interface Implementation
        /// <summary>
        /// 
        /// </summary>
        /// <param name="otherBaseMap"></param>
        /// <returns></returns>
        public int CompareTo( BaseMap otherMap )
        {
            if ( otherMap == null )
                return 1;

            return m_MapId.CompareTo( otherMap.m_MapId );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="xObject"></param>
        /// <returns></returns>
        public int CompareTo( object xObject )
        {
            return CompareTo( xObject as BaseMap );
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private SliceSupport m_SliceSupport = new SliceSupport();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool InSliceQueue()
        {
            return m_SliceSupport.InSliceQueue();
        }

        /// <summary>
        /// 
        /// </summary>
        public void OutSliceQueue()
        {
            m_SliceSupport.OutSliceQueue();
        }
        #endregion

        #region zh-CHS 私有事件 | en Private Event

        #region zh-CHS InitMap事件 | en Public Event
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<MapEventArgs> EventInitMap;
        #endregion

        #region zh-CHS PartitionSpace事件 | en Public Event
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<PartitionSpaceEventArgs> EventPartitionSpace;
        #endregion

        #region zh-CHS GetSpaceNode事件 | en Public Event
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<GetSpaceNodeEventArgs> EventGetSpaceNode;
        #endregion

        #region zh-CHS GetGetSpaceNodesInRange事件 | en Public Event
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<GetGetSpaceNodesInRangeEventArgs> EventGetSpaceNodesInRange;
        #endregion

        #endregion

        #region zh-CHS 共有事件 | en Public Event

        #region zh-CHS CanSpawn事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<CanSpawnEventArgs> m_EventCanSpawn;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventCanSpawn = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<CanSpawnEventArgs> EventCanSpawn
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventCanSpawn );
                {
                    m_EventCanSpawn += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventCanSpawn );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventCanSpawn );
                {
                    m_EventCanSpawn -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventCanSpawn );
            }
        }
        #endregion

        #region zh-CHS PlayersInRange事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<PlayersInRangeEventArgs> m_EventPlayersInRange;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventPlayersInRange = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<PlayersInRangeEventArgs> EventPlayersInRange
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventPlayersInRange );
                {
                    m_EventPlayersInRange += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventPlayersInRange );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventPlayersInRange );
                {
                    m_EventPlayersInRange -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventPlayersInRange );
            }
        }
        #endregion

        #region zh-CHS CreatureInRange事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<CreaturesInRangeEventArgs> m_EventCreaturesInRange;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventCreaturesInRange = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<CreaturesInRangeEventArgs> EventCreaturesInRange
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventCreaturesInRange );
                {
                    m_EventCreaturesInRange += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventCreaturesInRange );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventCreaturesInRange );
                {
                    m_EventCreaturesInRange -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventCreaturesInRange );
            }
        }
        #endregion

        #region zh-CHS Slice事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<MapEventArgs> m_EventSlice;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventSlice = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<MapEventArgs> Slice
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventSlice );
                {
                    m_EventSlice += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventSlice );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventSlice );
                {
                    m_EventSlice -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventSlice );
            }
        }
        #endregion

        #region zh-CHS BeforeEntityEnterMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeEntityEnterMapEventArgs> m_EventBeforeEntityEnterMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeEntityEnterMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeEntityEnterMapEventArgs> BeforeEntityEnterMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeEntityEnterMap );
                {
                    m_EventBeforeEntityEnterMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeEntityEnterMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeEntityEnterMap );
                {
                    m_EventBeforeEntityEnterMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeEntityEnterMap );
            }
        }
        #endregion

        #region zh-CHS AfterEntityEnterMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterEntityEnterMapEventArgs> m_EventAfterEntityEnterMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterEntityEnterMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterEntityEnterMapEventArgs> AfterEntityEnterMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterEntityEnterMap );
                {
                    m_EventAfterEntityEnterMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterEntityEnterMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterEntityEnterMap );
                {
                    m_EventAfterEntityEnterMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterEntityEnterMap );
            }
        }
        #endregion

        #region zh-CHS BeforeEntityLeaveMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeEntityLeaveMapEventArgs> m_EventBeforeEntityLeaveMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeEntityLeaveMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeEntityLeaveMapEventArgs> BeforeEntityLeaveMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeEntityLeaveMap );
                {
                    m_EventBeforeEntityLeaveMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeEntityLeaveMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeEntityLeaveMap );
                {
                    m_EventBeforeEntityLeaveMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeEntityLeaveMap );
            }
        }
        #endregion

        #region zh-CHS AfterEntityLeaveMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterEntityLeaveMapEventArgs> m_EventAfterEntityLeaveMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterEntityLeaveMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterEntityLeaveMapEventArgs> AfterEntityLeaveMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterEntityLeaveMap );
                {
                    m_EventAfterEntityLeaveMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterEntityLeaveMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterEntityLeaveMap );
                {
                    m_EventAfterEntityLeaveMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterEntityLeaveMap );
            }
        }
        #endregion

        #region zh-CHS BeforeEntityMoveInMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeEntityMoveInMapEventArgs> m_EventBeforeEntityMoveInMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeEntityMoveInMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeEntityMoveInMapEventArgs> BeforeEntityMoveInMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeEntityMoveInMap );
                {
                    m_EventBeforeEntityMoveInMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeEntityMoveInMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeEntityMoveInMap );
                {
                    m_EventBeforeEntityMoveInMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeEntityMoveInMap );
            }
        }
        #endregion

        #region zh-CHS AfterEntityMoveInMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterEntityMoveInMapEventArgs> m_EventAfterEntityMoveInMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterEntityMoveInMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterEntityMoveInMapEventArgs> AfterEntityMoveInMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterEntityMoveInMap );
                {
                    m_EventAfterEntityMoveInMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterEntityMoveInMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterEntityMoveInMap );
                {
                    m_EventAfterEntityMoveInMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterEntityMoveInMap );
            }
        }
        #endregion

        #region zh-CHS BeforeItemEnterMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeItemEnterMapEventArgs> m_EventBeforeItemEnterMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeItemEnterMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeItemEnterMapEventArgs> BeforeItemEnterMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeItemEnterMap );
                {
                    m_EventBeforeItemEnterMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeItemEnterMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeItemEnterMap );
                {
                    m_EventBeforeItemEnterMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeItemEnterMap );
            }
        }
        #endregion

        #region zh-CHS AfterItemEnterMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterItemEnterMapEventArgs> m_EventAfterItemEnterMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterItemEnterMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterItemEnterMapEventArgs> AfterItemEnterMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterItemEnterMap );
                {
                    m_EventAfterItemEnterMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterItemEnterMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterItemEnterMap );
                {
                    m_EventAfterItemEnterMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterItemEnterMap );
            }
        }
        #endregion

        #region zh-CHS BeforeItemLeaveMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeItemLeaveMapEventArgs> m_EventBeforeItemLeaveMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeItemLeaveMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeItemLeaveMapEventArgs> BeforeItemLeaveMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeItemLeaveMap );
                {
                    m_EventBeforeItemLeaveMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeItemLeaveMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeItemLeaveMap );
                {
                    m_EventBeforeItemLeaveMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeItemLeaveMap );
            }
        }
        #endregion

        #region zh-CHS AfterItemLeaveMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterItemLeaveMapEventArgs> m_EventAfterItemLeaveMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterItemLeaveMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterItemLeaveMapEventArgs> AfterItemLeaveMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterItemLeaveMap );
                {
                    m_EventAfterItemLeaveMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterItemLeaveMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterItemLeaveMap );
                {
                    m_EventAfterItemLeaveMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterItemLeaveMap );
            }
        }
        #endregion

        #region zh-CHS BeforeItemMoveInMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeItemMoveInMapEventArgs> m_EventBeforeItemMoveInMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeItemMoveInMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeItemMoveInMapEventArgs> BeforeItemMoveInMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeItemMoveInMap );
                {
                    m_EventBeforeItemMoveInMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeItemMoveInMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeItemMoveInMap );
                {
                    m_EventBeforeItemMoveInMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeItemMoveInMap );
            }
        }
        #endregion

        #region zh-CHS AfterItemMoveInMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterItemMoveInMapEventArgs> m_EventAfterItemMoveInMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterItemMoveInMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterItemMoveInMapEventArgs> AfterItemMoveInMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterItemMoveInMap );
                {
                    m_EventAfterItemMoveInMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterItemMoveInMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterItemMoveInMap );
                {
                    m_EventAfterItemMoveInMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterItemMoveInMap );
            }
        }
        #endregion

        #region zh-CHS BeforeCreatureEnterMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeCreatureEnterMapEventArgs> m_EventBeforeCreatureEnterMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeCreatureEnterMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeCreatureEnterMapEventArgs> BeforeCreatureEnterMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCreatureEnterMap );
                {
                    m_EventBeforeCreatureEnterMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCreatureEnterMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCreatureEnterMap );
                {
                    m_EventBeforeCreatureEnterMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCreatureEnterMap );
            }
        }
        #endregion

        #region zh-CHS AfterCreatureEnterMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterCreatureEnterMapEventArgs> m_EventAfterCreatureEnterMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterCreatureEnterMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterCreatureEnterMapEventArgs> AfterCreatureEnterMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCreatureEnterMap );
                {
                    m_EventAfterCreatureEnterMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCreatureEnterMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCreatureEnterMap );
                {
                    m_EventAfterCreatureEnterMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCreatureEnterMap );
            }
        }
        #endregion

        #region zh-CHS BeforeCreatureLeaveMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeCreatureLeaveMapEventArgs> m_EventBeforeCreatureLeaveMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeCreatureLeaveMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeCreatureLeaveMapEventArgs> BeforeCreatureLeaveMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCreatureLeaveMap );
                {
                    m_EventBeforeCreatureLeaveMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCreatureLeaveMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCreatureLeaveMap );
                {
                    m_EventBeforeCreatureLeaveMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCreatureLeaveMap );
            }
        }
        #endregion

        #region zh-CHS AfterCreatureLeaveMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterCreatureLeaveMapEventArgs> m_EventAfterCreatureLeaveMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterCreatureLeaveMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterCreatureLeaveMapEventArgs> AfterCreatureLeaveMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCreatureLeaveMap );
                {
                    m_EventAfterCreatureLeaveMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCreatureLeaveMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCreatureLeaveMap );
                {
                    m_EventAfterCreatureLeaveMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCreatureLeaveMap );
            }
        }
        #endregion

        #region zh-CHS BeforeCreatureMoveInMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeCreatureMoveInMapEventArgs> m_EventBeforeCreatureMoveInMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeCreatureMoveInMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeCreatureMoveInMapEventArgs> BeforeCreatureMoveInMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCreatureMoveInMap );
                {
                    m_EventBeforeCreatureMoveInMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCreatureMoveInMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCreatureMoveInMap );
                {
                    m_EventBeforeCreatureMoveInMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCreatureMoveInMap );
            }
        }
        #endregion

        #region zh-CHS AfterCreatureMoveInMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterCreatureMoveInMapEventArgs> m_EventAfterCreatureMoveInMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterCreatureMoveInMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterCreatureMoveInMapEventArgs> AfterCreatureMoveInMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCreatureMoveInMap );
                {
                    m_EventAfterCreatureMoveInMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCreatureMoveInMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCreatureMoveInMap );
                {
                    m_EventAfterCreatureMoveInMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCreatureMoveInMap );
            }
        }
        #endregion

        #region zh-CHS BeforeCharacterEnterMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeCharacterEnterMapEventArgs> m_EventBeforeCharacterEnterMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeCharacterEnterMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeCharacterEnterMapEventArgs> BeforeCharacterEnterMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCharacterEnterMap );
                {
                    m_EventBeforeCharacterEnterMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCharacterEnterMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCharacterEnterMap );
                {
                    m_EventBeforeCharacterEnterMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCharacterEnterMap );
            }
        }
        #endregion

        #region zh-CHS AfterCharacterEnterMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterCharacterEnterMapEventArgs> m_EventAfterCharacterEnterMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterCharacterEnterMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterCharacterEnterMapEventArgs> AfterCharacterEnterMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCharacterEnterMap );
                {
                    m_EventAfterCharacterEnterMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCharacterEnterMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCharacterEnterMap );
                {
                    m_EventAfterCharacterEnterMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCharacterEnterMap );
            }
        }
        #endregion

        #region zh-CHS BeforeCharacterLeaveMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeCharacterLeaveMapEventArgs> m_EventBeforeCharacterLeaveMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeCharacterLeaveMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeCharacterLeaveMapEventArgs> BeforeCharacterLeaveMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCharacterLeaveMap );
                {
                    m_EventBeforeCharacterLeaveMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCharacterLeaveMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCharacterLeaveMap );
                {
                    m_EventBeforeCharacterLeaveMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCharacterLeaveMap );
            }
        }
        #endregion

        #region zh-CHS AfterCharacterLeaveMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterCharacterLeaveMapEventArgs> m_EventAfterCharacterLeaveMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterCharacterLeaveMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterCharacterLeaveMapEventArgs> AfterCharacterLeaveMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCharacterLeaveMap );
                {
                    m_EventAfterCharacterLeaveMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCharacterLeaveMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCharacterLeaveMap );
                {
                    m_EventAfterCharacterLeaveMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCharacterLeaveMap );
            }
        }
        #endregion

        #region zh-CHS BeforeCharacterMoveInMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<BeforeCharacterMoveInMapEventArgs> m_EventBeforeCharacterMoveInMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventBeforeCharacterMoveInMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<BeforeCharacterMoveInMapEventArgs> BeforeCharacterMoveInMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCharacterMoveInMap );
                {
                    m_EventBeforeCharacterMoveInMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCharacterMoveInMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventBeforeCharacterMoveInMap );
                {
                    m_EventBeforeCharacterMoveInMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventBeforeCharacterMoveInMap );
            }
        }
        #endregion

        #region zh-CHS AfterCharacterMoveInMap事件 | en Public Event
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<AfterCharacterMoveInMapEventArgs> m_EventAfterCharacterMoveInMap;
        /// <summary>
        /// 
        /// </summary>
        private ReaderWriterLockSlim m_LockEventAfterCharacterMoveInMap = new ReaderWriterLockSlim();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<AfterCharacterMoveInMapEventArgs> AfterCharacterMoveInMap
        {
            add
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCharacterMoveInMap );
                {
                    m_EventAfterCharacterMoveInMap += value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCharacterMoveInMap );
            }
            remove
            {
                ReaderWriterLockSlimEx.EnterWriteLock( m_LockEventAfterCharacterMoveInMap );
                {
                    m_EventAfterCharacterMoveInMap -= value;
                }
                ReaderWriterLockSlimEx.ExitWriteLock( m_LockEventAfterCharacterMoveInMap );
            }
        }
        #endregion

        #endregion

        #region zh-CHS IComponent接口实现 | en IComponent Interface Implementation

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private ComponentHandler m_ComponentHandler = new ComponentHandler();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public ComponentId ComponentId
        {
            get { return m_ComponentHandler.ComponentId; }
            set { m_ComponentHandler.ComponentId = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public IComponentHandler ComponentOwner
        {
            get { return m_ComponentHandler.ComponentOwner; }
            set { m_ComponentHandler.ComponentOwner = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="componentMessage"></param>
        public virtual void OnHandleComponentMessage( ComponentMessage componentMessage )
        {
            m_ComponentHandler.OnHandleComponentMessage( componentMessage );
        }

        #endregion

        #region zh-CHS IComponentHandler接口实现 | en IComponentHandler Interface Implementation
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="componentId"></param>
        /// <param name="component"></param>
        public void RegisterComponent<T>( ComponentId componentId, T component ) where T : class, IComponent
        {
            m_ComponentHandler.RegisterComponent<T>( componentId, component );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="componentId"></param>
        /// <returns></returns>
        public T GetComponent<T>( ComponentId componentId ) where T : class, IComponent
        {
            return m_ComponentHandler.GetComponent<T>( componentId );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="componentId"></param>
        /// <param name="componentMessage"></param>
        public void SubScribeComponentMessage( ComponentId componentId, ComponentMessage componentMessage )
        {
            m_ComponentHandler.SubScribeComponentMessage( componentId, componentMessage );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="componentMessage"></param>
        public void PostComponentMessage( ComponentMessage componentMessage )
        {
            m_ComponentHandler.PostComponentMessage( componentMessage );
        }
        #endregion
    }
}
#endregion

